package org.blogwu.learn.multithread.chapter2.demo3.v2;


public class Main {

    static Object o1 = new Object();

    static Object o2 = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (o1) {
                synchronized (o2) {
                    try {
                        System.out.println("t1发起o2等待");
                        o1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        });

        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t2");
            synchronized (o1) {
                System.out.println("t2 o1进来了");
                synchronized (o2) {
                    System.out.println("t2 o2进来了");
                }
            }

        });

        t1.start();
        t2.start();
    }

}
